home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / MacOS / MacZString.h < prev   
Encoding:
C/C++ Source or Header  |  2001-06-23  |  3.5 KB  |  160 lines

  1. /*==================================================================
  2.     File:        MacZString.h
  3.     
  4.     Contains:    Mac-specific parsing for ZStrings.
  5.  
  6.     Written by:    Eric Traut
  7.     
  8.     Copyright:    2000-2001 Connectix Corporation
  9.     
  10.     This source has been placed into the public domain by
  11.     Connectix Corporation. You have the right to modify, 
  12.     distribute or use this code without any legal limitations
  13.     or finanicial/licensing requirements. Connectix is not 
  14.     liable for any problems that result from the use of this 
  15.     code.
  16.     
  17.     If you have comments, feedback, questions, or would like
  18.     to submit bug fixes or updates to this code, please email
  19.     opensource@connectix.com.
  20. ==================================================================*/
  21.  
  22. #ifndef __MACZSTRING__
  23. #define __MACZSTRING__
  24.  
  25.  
  26. #include "ZString.h"
  27. #include "ZStringParser.h"
  28.  
  29. #include <Resources.h>
  30. #include <Menus.h>
  31.  
  32. enum
  33. {
  34.     kZStringOverrideDictionaryResType        = 'ZOvr',
  35.     kZStringTwoByteTableResType                = 'ZTBt',
  36.     
  37.     // To override the default behavior (i.e.
  38.     // choosing the language based on the system
  39.     // software), put a two-byte ID inside the 
  40.     // following resource.
  41.     kZStringLanguageSpecifierResType        = 'ZLan',
  42.     kZStringLanguageSpecifierID                = 128
  43.  
  44. };
  45.  
  46.  
  47. /*==================================================================
  48.     ZString
  49. ==================================================================*/
  50.  
  51. class MacZString : public ZString
  52. {
  53.     public:
  54.         // Initialization & Teardown
  55.         static void
  56.         Initialize();
  57.         
  58.         static void
  59.         TearDown();
  60.         
  61.         static void
  62.         GetNamedPString(
  63.             const char *        inNamedString,
  64.             StringPtr            outPString,
  65.             Z_UInt32            inMaxLength             = 255,
  66.             Z_Boolean            inDataIsVolatile    = false);
  67.         
  68.         static void
  69.         GetNamedPString(
  70.             ConstStringPtr        inNamedString,
  71.             StringPtr            outPString,
  72.             Z_UInt32            inMaxLength             = 255,
  73.             Z_Boolean            inDataIsVolatile    = false);
  74.         
  75.         static UInt8
  76.         ExtractMenuInfo(
  77.             const char *        inMenuZString,
  78.             Str255                outMenuItemText);
  79.  
  80.         static void
  81.         BuildMenu(
  82.             MenuHandle            inMenuHandle,
  83.             const char **        inMenuInfo,
  84.             Boolean                inInsertMenu = true);
  85.  
  86.         static void
  87.         LoadOverrideDictionary(
  88.             ResID                inOverrideID);
  89.         
  90.         static ResID
  91.         CalculateFontInfoBaseID(
  92.             ResID                inOverrideID);
  93.         
  94.         static ResID
  95.         CalcOverrideDictionaryID();
  96.         
  97.         // Replacing Substrings
  98.         ZString
  99.         ReplaceParameter(
  100.             Z_UInt8                inParamNum,
  101.             const char *        inString)
  102.             { return ZString::ReplaceParameter(inParamNum, inString); }
  103.  
  104.         ZString
  105.         ReplaceParameter(
  106.             Z_UInt8                inParamNum,
  107.             Z_SInt32            inNumber)
  108.             { return ZString::ReplaceParameter(inParamNum, inNumber); }
  109.         
  110.         ZString
  111.         ReplaceParameter(
  112.             Z_UInt8                inParamNum,
  113.             ConstStringPtr        inString);
  114.  
  115.     public:
  116.         static Handle    sOverrideHandle;
  117. };
  118.  
  119.  
  120. /*==================================================================
  121.     MacZStringParser
  122. ==================================================================*/
  123.  
  124. class MacZStringParser : public ZStringParser
  125. {
  126.     public:
  127.         virtual UInt16
  128.         GetTagReplacement(
  129.             ZStringTagID                inTagID,
  130.             char *                        outReplacement);
  131. };
  132.  
  133.  
  134. /*==================================================================
  135.     MacZStringInitializer
  136.     
  137.     This class is suitable for use as a stack-based initializer when
  138.     using ZString in standalone code modules that are loaded and
  139.     unloaded between calls.
  140. ==================================================================*/
  141.  
  142. class MacZStringInitializer
  143. {
  144.     public:
  145.         MacZStringInitializer()
  146.         {
  147.             MacZString::Initialize();
  148.             MacZString::LoadOverrideDictionary(MacZString::CalcOverrideDictionaryID());
  149.         }
  150.         
  151.         ~MacZStringInitializer()
  152.         {
  153.             MacZString::TearDown();
  154.         }
  155. };
  156.  
  157. #endif // __MACZSTRING__
  158.  
  159.  
  160.